package com.xtayfjpk.zookeeper.test.master_workers.callback.master;

import org.apache.log4j.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;
import org.apache.zookeeper.data.Stat;

import com.xtayfjpk.zookeeper.test.master_workers.Master;
import com.xtayfjpk.zookeeper.test.master_workers.RecreateTaskCtx;
import com.xtayfjpk.zookeeper.test.master_workers.callback.BaseDataCallback;

public class GetDataReassignCallback extends BaseDataCallback {
	private static final Logger LOGGER = Logger.getLogger(GetDataReassignCallback.class);
	private Master master;
	
	public GetDataReassignCallback(Master master) {
		this.master = master;
	}
	
	@Override
	protected void connectionLossCaseAction(int rc, String path, Object ctx,
			byte[] data, Stat stat) {
		master.getDataReassign(path, (String) ctx);
	}
	
	@Override
	protected void okCaseAction(int rc, String path, Object ctx, byte[] data, Stat stat) {
		//重新创建任务
		master.recreateTask(new RecreateTaskCtx(path, (String)ctx, data));
	}
	
	@Override
	protected void defaultCaseAction(int rc, String path, Object ctx, byte[] data, Stat stat) {
		LOGGER.error("Something went wrong when getting data ",
                KeeperException.create(Code.get(rc)));
	}
}
